import utime
from machine import ADC,Pin,I2C

ADDRESS=56
def aht10Init():
    i2c.writeto(ADDRESS,b"\xe1\x08\x00")
    utime.sleep_ms(100)
def Measurement():
    i2c.writeto(ADDRESS,b"\xac\x33\x00")
def aht10Get():
    raw=i2c.readfrom(ADDRESS,7)
    _temp= ((raw[3] & 0xF) << 16) | (raw[4] << 8) | raw[5]
    _temp = ((_temp * 200.0) / 0x100000) - 50
    _humidity = (raw[1] << 12) | (raw[2] << 4) | (raw[3] >> 4)
    _humidity = (_humidity * 100) / 0x100000
    return (_temp,_humidity)
if __name__=="__main__":
    import lc
    i2c = I2C(0,scl=Pin(lc.scl), sda=Pin(lc.sda),freq=400000)
    # i2c.scan()
    # i2c.writeto(ADDRESS,b"\xba")
    # utime.sleep_ms(100)
    i2c.writeto(ADDRESS,b"\xe1\x08\x00")
    utime.sleep_ms(100)
    i2c.writeto(ADDRESS,b"\xac\x33\x00")
    utime.sleep_ms(100)
    raw=i2c.readfrom(ADDRESS,7)
    _temp= ((raw[3] & 0xF) << 16) | (raw[4] << 8) | raw[5]
    _temp = ((_temp * 200.0) / 0x100000) - 50
    _humidity = (raw[1] << 12) | (raw[2] << 4) | (raw[3] >> 4)
    _humidity = (_humidity * 100) / 0x100000
    print(raw)
    print(_temp,_humidity)
